<?php


namespace app\adminapi\controller\system;


use app\adminapi\BaseAdminController;
use app\adminapi\dao\member\MemberLevelDao;
use app\adminapi\dao\system\SysMenuDao;
use app\adminapi\lists\member\MemberLevelLists;
use app\adminapi\lists\system\SysMenuLists;
use app\adminapi\validate\member\MemberLevelValidate;
use app\adminapi\validate\system\SysMenuValidate;

/**
 * @projectName src
 */
class SysMenu extends BaseAdminController
{
    public function add()
    {
        $params = (new SysMenuValidate())->post([
            'parent_id'=>0,
            'menu_type',
            'menu_name',
        ])->goCheck('add');
        SysMenuDao::add($params);
        return $this->success('添加成功', [], 200, 1);
    }

    public function edit()
    {
        $params = (new SysMenuValidate())->post([
            'id',
            'parent_id'=>0,
            'menu_type',
            'menu_name',
        ])->goCheck('edit');
        $result = SysMenuDao::edit($params);
        if (true === $result) {
            return $this->success('编辑成功', [], 200, 1);
        }
        return $this->fail(SysMenuDao::getError());
    }

    public function delete()
    {
        $params = (new SysMenuValidate())->post([
            'id'
        ])->goCheck('delete');
        SysMenuDao::delete($params);
        return $this->success('删除成功', [], 200, 1);
    }

    public function detail()
    {
        $params = (new SysMenuValidate())->get([
            'id'
        ])->goCheck('detail');
        $result = SysMenuDao::detail($params);
        return $this->data($result);
    }

    public function all()
    {
        $result = SysMenuDao::getAllData();
        return $this->data($result);
    }

    /**
     * 获取列表
     */
    public function lists()
    {
        return $this->dataLists(new SysMenuLists());
    }

}